package br.com.management.mentor.view.core.menu.handlers;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.springframework.beans.factory.annotation.Autowired;

import br.com.management.mentor.model.entities.view.Menu;
import br.com.management.mentor.view.core.ViewManager;
import br.com.management.mentor.view.core.menu.MenuHandler;
import br.com.management.mentor.view.users.Create;
import br.com.management.mentor.view.users.List;

public class UserMenuHandler implements MenuHandler {

	@Autowired
	private ViewManager manager;
	
	@Autowired
	private Create createView;
	
	@Autowired
	private List listView;

	@Override
	public boolean canHandle( Menu menu ) {
		return menu.getKey().equals( "menu.users" );
	}

	@Override
	public void handle( Menu menu ) {

		TabFolder folder = new TabFolder( manager.getViewsContainer() , SWT.BORDER );

		TabItem tab1 = new TabItem( folder , SWT.NONE );
		tab1.setText( "Listagem" );
		
		SashForm sashForm = new SashForm(folder, SWT.HORIZONTAL);
	    tab1.setControl(sashForm);
	    
	    listView.build( sashForm );
		
		TabItem tab2 = new TabItem( folder , SWT.NONE );
		tab2.setText( "Cadastro" );

		SashForm sashForm2 = new SashForm(folder, SWT.HORIZONTAL);
	    tab2.setControl(sashForm2);
		
	    createView.build( sashForm2 );
	    
		folder.pack();
		manager.getViewsContainer().update();
	}

}